package com.example.yuejian.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian.Bean.Club;
import com.example.yuejian.R;
import com.example.yuejian.UnitData;
import com.example.yuejian.activity.ClubDetail;
import com.squareup.picasso.Picasso;

import java.util.List;


public class     ClublistAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
private Context mContext;
private List<Club.ClublistBean> mList;
public LayoutInflater mLayoutInflater;

public ClublistAdapter(Context mContext, List<Club.ClublistBean> List) {
        this.mContext = mContext;
        this.mList = List;
        mLayoutInflater = LayoutInflater.from(mContext);
        }

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.clublist, parent, false);
        ViewHolder v = new ViewHolder(view);

        return v;
        }

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final Club.ClublistBean club = (Club.ClublistBean) mList.get(position);
        if (null == club)
        return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.name.setText(club.getClubname());
        viewHolder.intro.setText(club.getClubbrief());
        if(!club.getClubpic().isEmpty()) {
        Picasso.with(mContext).load(UnitData.IMG_URL+club.getClubpic()).into(viewHolder.img_club);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
        Intent intent = new Intent(mContext, ClubDetail.class);
        Bundle bundle = new Bundle();
        bundle.putInt("clubid",club.getId());
        bundle.putString("clubintro",club.getClubbrief());
        bundle.putString("clubname",club.getClubname());
        bundle.putString("clubaddress",club.getClubaddr());
        bundle.putString("clubtel",club.getClubtele());
        bundle.putString("clubtime",club.getClubtime());
        bundle.putString("pic", UnitData.IMG_URL+club.getClubpic());
        intent.putExtras(bundle);
        mContext.startActivity(intent);
        }
        });
        }

@Override
public int getItemCount() {
        return mList.size();
        }


public class ViewHolder extends RecyclerView.ViewHolder {
    TextView name,intro;
    ImageView img_club;

    public ViewHolder(View itemView) {
        super(itemView);
        name = (TextView) itemView.findViewById(R.id.name);
        intro = (TextView) itemView.findViewById(R.id.intro);
        img_club = (ImageView) itemView.findViewById(R.id.img_club);

    }
}
}
